package org.dromara.oce.controller.admin;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.oce.domain.qo.OceProductUrlQo;
import org.dromara.oce.domain.vo.OceProductUrlVo;
import org.dromara.oce.domain.bo.OceProductUrlBo;
import org.dromara.oce.service.OceProductUrlService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 端原生短剧链接
 *
 * @author dsbb
 * @date 2025-06-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oce/productUrl")
public class OceProductUrlController extends BaseController {

    private final OceProductUrlService oceProductUrlService;

    /**
     * 查询端原生短剧链接列表
     */
    @SaCheckPermission("oce:productUrl:list")
    @GetMapping("/list")
    public TableDataInfo<OceProductUrlVo> list(OceProductUrlQo qo, PageQuery pageQuery) {
        return oceProductUrlService.queryPageList(qo, pageQuery);
    }

    /**
     * 导出端原生短剧链接列表
     */
    @SaCheckPermission("oce:productUrl:export")
    @Log(title = "端原生短剧链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OceProductUrlQo qo, HttpServletResponse response) {
        List<OceProductUrlVo> list = oceProductUrlService.queryList(qo);
        ExcelUtil.exportExcel(list, "端原生短剧链接", OceProductUrlVo.class, response);
    }

    /**
     * 获取端原生短剧链接详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("oce:productUrl:query")
    @GetMapping("/{id}")
    public R<OceProductUrlVo> getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable Long id) {
        return R.ok(oceProductUrlService.queryById(id));
    }

    /**
     * 新增端原生短剧链接
     */
    @SaCheckPermission("oce:productUrl:add")
    @Log(title = "端原生短剧链接", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OceProductUrlBo bo) {
        return toAjax(oceProductUrlService.insertByBo(bo));
    }

    /**
     * 修改端原生短剧链接
     */
    @SaCheckPermission("oce:productUrl:edit")
    @Log(title = "端原生短剧链接", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OceProductUrlBo bo) {
        return toAjax(oceProductUrlService.updateByBo(bo));
    }

    /**
     * 删除端原生短剧链接
     *
     * @param ids 主键串
     */
    @SaCheckPermission("oce:productUrl:remove")
    @Log(title = "端原生短剧链接", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(oceProductUrlService.deleteWithValidByIds(List.of(ids), true));
    }
}
